package lottery;

import java.awt.Color;
import java.awt.Font;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.GroupLayout;  
import javax.swing.GroupLayout.Alignment;  
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;  
import javax.swing.JPasswordField;  
import javax.swing.JRadioButton;  
import javax.swing.JTextField;

import dao.DaoFactory;
import dao.User;
import dao.UserDao;  
public class RegisterFrame extends JFrame {  
    
    JLabel label1;  
    JLabel label2;  
    JLabel label3;  
    JLabel label4;
    JLabel label5;
    JTextField tf1;  
    JTextField tf2; 
    JTextField tf3; 
    JTextField tf4; 
    
  
    JButton bt1;  
    JButton bt2;  
  
    public RegisterFrame() {  
        this.setVisible(true);  
        this.setSize(400, 250);  
        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        int width = Toolkit.getDefaultToolkit().getScreenSize().width;
		int height = Toolkit.getDefaultToolkit().getScreenSize().height;
        this.setVisible(true);  
        super.setLocation((width - 400) / 2, (height - 350) / 2);  
        getContentPane().setBackground(Color.CYAN);
        label1 = new JLabel("用户信息");  
        label1.setFont(new Font("宋体", 1, 20)); // NOI18N
        label1.setText("请填写信息");
        
        
        
        label2 = new JLabel("ID：");  
        label3 = new JLabel("用户名："); 
        label4 = new JLabel("密码：");
        label5 = new JLabel("电话号码：");
        
        tf1 = new JTextField();  
        tf2 = new JTextField(); 
        tf3= new JTextField(); 
        tf4= new JTextField();  
        bt1 = new JButton("确定注册");
        bt2 =new JButton("返回");
        
        bt1.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                User user = new User();
                user.setId(Integer.parseInt(tf1.getText()));
                user.setUsername(tf2.getText());
                user.setPassword(tf3.getText());
                user.setTelNum(tf4.getText());
                UserDao userDao = DaoFactory.getUserDaoInstance();
                try {
					userDao.Insert(user);
				} catch (Exception e1) {
					// TODO Auto-generated catch block
					e1.printStackTrace();
				}
            }
        });
        bt2.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
            	setVisible(false);
            }
        });
        // 为指定的 Container 创建 GroupLayout  
        GroupLayout layout = new GroupLayout(this.getContentPane());  
        this.getContentPane().setLayout(layout);  
        //创建GroupLayout的水平连续组，，越先加入的ParallelGroup，优先级级别越高。  
        
        GroupLayout.SequentialGroup hGroup = layout.createSequentialGroup();  
       hGroup.addGap(60);//添加间隔  
        hGroup.addGroup(layout.createParallelGroup().addComponent(label2)  
                .addComponent(label3).addComponent(label4).addComponent(label5)
                .addComponent(bt1));  
        hGroup.addGap(5);  
        hGroup.addGroup(layout.createParallelGroup().addComponent(label1)  
                .addComponent(tf1).addComponent(tf2).addComponent(tf3)  
                .addComponent(tf4).addComponent(bt2));  
        hGroup.addGap(60);  
        layout.setHorizontalGroup(hGroup);  
        //创建GroupLayout的垂直连续组，，越先加入的ParallelGroup，优先级级别越高。  
        GroupLayout.SequentialGroup vGroup = layout.createSequentialGroup();  
        vGroup.addGap(20);  
        vGroup.addGroup(layout.createParallelGroup().addComponent(label1));  
        vGroup.addGap(10);  
        vGroup.addGroup(layout.createParallelGroup().addComponent(label2)  
                .addComponent(tf1));  
        vGroup.addGap(10);  
        vGroup.addGroup(layout.createParallelGroup().addComponent(label3)  
                .addComponent(tf2));  
        vGroup.addGap(10); 
        vGroup.addGroup(layout.createParallelGroup().addComponent(label4).addComponent(tf3));  
        vGroup.addGap(10); 
        vGroup.addGroup(layout.createParallelGroup().addComponent(label5).addComponent(tf4));
        vGroup.addGap(10);
        vGroup.addGroup(layout.createParallelGroup(Alignment.TRAILING) 
        		.addComponent(bt1)
                .addComponent(bt2));  
        vGroup.addGap(20);  
        //设置垂直组  
        layout.setVerticalGroup(vGroup);  
        //pack();
        
    }  
}  